<?php
//接收数据账号和密码
$news_title = $_POST['news_title'];
$news_url = $_POST['news_url'];
//连接数据库
$dbh = new PDO('mysql:host=127.0.0.1;dbname=1105', "root", "root");
//防sql注入
$news_title = $dbh->quote($news_title);
$news_url = $dbh->quote($news_url);
//查询的sql语句
$sql = "insert into news (news_title,news_url) value ($news_title,$news_url) ";
//执行sql语句
$res = $dbh->exec($sql);
//判断是否添加成功
if($res){
    $arr['code'] = 0;
    $arr['msg'] = '添加成功';
    $arr['data'] = [];
}else{
    $arr['code'] = 1;
    $arr['msg'] = '添加失败';
    $arr['data'] = [];
}
//返回json格式的数据
echo json_encode($arr);
